﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;

namespace FirmaTransportowa
{
    public partial class LoginForm : Form
    {
        LoginPresenter loginPresenter;

        public LoginForm(LoginPresenter presenter)
        {
            InitializeComponent();
            loginPresenter = presenter;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            errorPassword.Text = String.Empty;
            passwordLabel.ForeColor = Color.Black;
        }

        private void loginBox_TextChanged(object sender, EventArgs e)
        {
            errorLogin.Text = String.Empty;
            loginLabel.ForeColor = Color.Black;
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                Application.Exit();
            }
        }

        // wywołanie logowania po naciśnięciu klawisza enter
        private void loginBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                loginPresenter.login();
            }
        }

        private void passwordBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                loginPresenter.login();
            }
        }

        private void login(object sender, EventArgs e)
        {
            loginPresenter.login();
        }

        private void LoginForm_HelpButtonClicked(object sender, CancelEventArgs e)
        {
            HelpUtils.showHelp(this, 1);
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.F1)
            {
                HelpUtils.showHelp(this, 1);
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    }
}